package java图形化界面;

import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class TestEvent {
    static JButton bt=new JButton("隐藏按钮");

    public static void main(String[] args) {
        Frame f=new Frame();
        f.setLocation(300,200);
        f.setSize(200,200);
//        取消布局管理器
        f.setLayout(null);
        bt.addMouseListener(new MouseMove());
        bt.setBackground(Color.yellow);
        bt.setBounds(new Rectangle(45,100,90,30));
        f.add(bt);
        f.pack();
        f.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                System.exit(0);
            }
        });
        f.setVisible(true);
    }
    }
class MouseMove extends MouseAdapter{
    public void mouseClicked(MouseEvent e){
//        鼠标单击，按钮消失
        TestEvent.bt.setVisible(false);
    }
//    鼠标移开按钮出现
    public void mouseExited(MouseEvent e){
        TestEvent.bt.setVisible(true);
    }
}